//---------------------------------------------------------------------------

#ifndef ClassFactoryH
#define ClassFactoryH
//---------------------------------------------------------------------------




#include <map>
using namespace std;

class abstractModule1Creator
{
public:
    virtual fooCreator() {}
    virtual Module1 * create() const = 0;
};

template <class C>
class Module1Creator : public abstractModule1Creator
{
public:
    virtual Module1 * create() const { return new C(); }
};

class Module1Factory
{
protected:
    typedef std::map<std::string, abstractModule1Creator*> FactoryMap;
    FactoryMap _factory;

public:
    Module1Factory(){};
    virtual ~Module1Factory(){};

    template <class C>
    void add(const std::string & id)
    {
        typename FactoryMap::iterator it = _factory.find(id);
        if (it == _factory.end())
            _factory[id] = new fooCreator<C>();
    }

    Module1 * create(const std::string & id)
    {
        typename FactoryMap::iterator it = _factory.find(id);
        if (it != _factory.end())
            return it->second->create();
        return 0;
    }

private:
    typename FactoryMap::iterator it;
};




#endif
